package srm520;

public class SRMCodingPhase {

    public int countScore(int[] points, int[] skills, int luck) {
        int a[] = new int[3], b[] = new int[3], p, t, max = 0;
        for (int i = 0; i < skills[0]; i++) {
            for (int j = 0; j < skills[1]; j++) {
                for (int k = 0; k < skills[2]; k++) {
                    if (i + j + k > luck) continue;
                    b[0] = skills[0]-i; b[1] = skills[1]-j; b[2] = skills[2]-k;
                    a[0] = points[0] - 2*b[0]; a[1] = points[1] - 4*b[1]; a[2] = points[2] - 8*b[2];
                    for (int m = 0; m < 1<<3; m++) {
                        p = 0; t = 0;
                        for (int n = 0; n < 3; n++) {
                            if (((1 << n) & m) != 0) {
                                p+=a[n]; t += b[n];
                            }
                        }
                        if(p>max && t<=75) max = p;
                    }
                }
            }
        }
        return max;
    }
}
